package cn.dxc.demo.config;


import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
/**
 * 当前使用swagger的默认配置
 */
@Api(value = "swagger配置")
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment environment) {
        /** 根据当前环境选择swagger显示
         * 通过Environment.acceptsProfiles()判断自己是否处于环境中
         */

        Profiles profiles = Profiles.of("dev");
        final boolean flag = environment.acceptsProfiles(profiles);


        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(flag)
                .groupName("wicking")
                .select()
                /**
                 * RequestHandlerSelectors: 配置要扫描接口的方式
                 *      basePackage :指定要扫描的包
                 *          any :扫描全部
                 *          none :不扫描
                 *      withClassAnnotation: 扫描类上的注解，参数是注解的反射对象
                 *      withMethodAnnotation() :扫描方法上的注解
                 */

                .apis(RequestHandlerSelectors.basePackage("cn.dxc.demo.controller"))
                /**
                 * paths: 过滤什么路径
                 */
                //.paths()
                .build();
    }


    @Bean
    public ApiInfo apiInfo() {

        final Contact contact = new Contact("陆俊", "https://gitee.com/wicking/spring-boot-project.git", "lu1227jun@163.com");

        return new ApiInfo(
                "SummerFirstDemo"
                , "DXC 暑期 Case"
                , "1.0", "https://gitee.com/"
                , contact
                , "Apache 2.0"
                , "http://www.apache.org/licenses/LICENSE-2.0"
                , new ArrayList());


    }


}
